<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/css/bootstrap.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/js/bootstrap.min.js"></script>

<script>

	$(document).ready(function(){
				
		var tableData;
		$(".allcolumn").empty();
		
		var sort = new Array();
		
		
		
		$.getJSON('http://localhost:8080/algorithm/dataList', function(data) {
			var start=new Date().getTime();
			$.each(data, function(key, value) {
				sort.push(value);
			});
			BubbleSort(sort);
			console.log((new Date().getTime())-start,"ms");
			
		});		
		
		function BubbleSort(sort){
			
			for(var i = 0; i < sort.length; i++){
				for(var j = 0; j < (sort.length - 1 - i); j++){
					if(sort[j].average < sort[j+1].average){
						var temp = sort;
						var tempA = sort[j];
						var tempB = sort[j+1];
						temp[j+1] = tempA;
						temp[j] = tempB;
						sort = temp;
					}
				}
			}			

			var tableData;
			for(var k = 0; k < sort.length; k++){				
				tableData = "<tr class='allcolumn'>";					
				tableData += "<td><a href=javascript:getView('"+sort[k].hakbun+"','"+sort[k].chasu+"')>"+sort[k].hakbun+"</a></td>";
				tableData += "<td>"+sort[k].chasu+"</td>";
				tableData += "<td>"+sort[k].name+"</td>";
				tableData += "<td>"+sort[k].criminal+"</td>";
				tableData += "<td>"+sort[k].civil+"</td>";
				tableData += "<td>"+sort[k].english+"</td>";
				tableData += "<td>"+sort[k].average+"</td>";
				tableData += "<td>"+(k+1)+"</td>";
				tableData += "</tr>";
				$("#tableData").append(tableData);				
				
			}
			
		}
		
	});		

	

</script>

</head>
<body>
	<div id="jsonData"></div>
	<div class="table-responsive">
		<table align="center" border="0" id="tableData" class="table">
			<tr align="center">
				<th>Hakbun</th>
				<th>Chasu</th>
				<th>Name</th>
				<th>Criminal</th>
				<th>Civil</th>
				<th>English</th>
				<th>Avarage</th>
				<th>Rank</th>
			</tr>
	</div>
</body>
</html>